package org.example.web;

import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;

@WebServlet(urlPatterns = "/servletDemo3", loadOnStartup = 1)
public class ServletDemo3 implements Servlet {
    private ServletConfig servletConfig;

    /**
     * 初始化方法
     * 只调用一次
     *
     * @param servletConfig
     * @throws ServletException
     */
    @Override
    public void init(ServletConfig servletConfig) throws ServletException {
        this.servletConfig = servletConfig;
        System.out.println("servletDemo3_init?");
    }

    @Override
    public ServletConfig getServletConfig() {
        return servletConfig;
    }

    /**
     * 提供服务，调用多次
     * 每一次Servlet被访问时调用
     *
     * @param servletRequest
     * @param servletResponse
     * @throws ServletException
     * @throws IOException
     */
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        System.out.println("servletDemo3_service?");
    }

    @Override
    public String getServletInfo() {
        return null;
    }

    /**
     * 销毁方法
     * 内存释放或服务器关闭的时候调用，Servlet对象会被销毁，只调用一次
     */
    @Override
    public void destroy() {
        System.out.println("servletDemo3_destroy?");

    }
}
